package fa7.socialcode.web;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ReverseComparator;

import fa7.socialcode.service.AvaliacaoManager;


public class AvaliacaoList implements Serializable {
		  private AvaliacaoManager avaliacaoManager;
		  private String sortColumn = "id";
		  private boolean ascending = true;

		  public String getSortColumn() {
		    return sortColumn;
		  }

		  public void setSortColumn(String sortColumn) {
		    this.sortColumn = sortColumn;
		  }

		  public boolean isAscending() {
		    return ascending;
		  }

		  public void setAscending(boolean ascending) {
		    this.ascending = ascending;
		  }

		  public void setAvaliacaoManager(AvaliacaoManager avaliacaoManager) {
		    this.avaliacaoManager = avaliacaoManager;
		  }

		  public List getAvaliacoes() {
		    List avaliacoes = avaliacaoManager.findAvaliacoes();

		    Comparator comparator = null;

		    comparator = new BeanComparator(sortColumn);

		    if (!ascending) {
		      comparator = new ReverseComparator(comparator);
		    }

		    Collections.sort(avaliacoes, comparator);

		    return avaliacoes;
		  }
		}
